<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="button" name="" id="" value="按钮1">
    <input type="button" name="" id="" value="按钮2">
    <input type="button" name="" id="" value="按钮3">
    <script>
        let aBtn = document.querySelectorAll('input');

        for (let i = 0; i < aBtn.length; i++) {
            aBtn[i].onclick = function () {
                alert(i);
            }
        }
    </script>
</body>

</html>